package com.gupao.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.ClientRegistrationException;
import org.springframework.security.oauth2.provider.client.BaseClientDetails;
import org.springframework.stereotype.Component;

import com.gupao.entity.AppSystem;
import com.gupao.service.AppSystemService;

@Component
public class OpenapiClientDetailsService implements ClientDetailsService{
	
	@Autowired
	AppSystemService appSystemService;

	public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
		AppSystem appSystem=appSystemService.selectByAppKey(clientId);
		BaseClientDetails details=new BaseClientDetails(clientId, Auth2ServerConfig.OPENAPI_RESOURCE_ID, "select", "client_credentials,refresh_token", "openapi");
		details.setClientSecret(appSystem.getAppSecret());
		return details;
	}

}
